package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Salary;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.qo.SalaryQuery;
import cn.wolfcode.service.IEmployeeService;
import cn.wolfcode.service.ISalaryService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryItemService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

@Controller
@RequestMapping("/salary")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @Autowired
    private IEmployeeService employeeService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") SalaryQuery qo){
        PageInfo<Salary> pageInfo = salaryService.query(qo);
        //查询所有的支付方式
        model.addAttribute("pay_type",systemDictionaryItemService.selectSystemDictionaryItemBySn("pay_type"));
        //查询所有员工
        model.addAttribute("employees",employeeService.selectAll());
        model.addAttribute("pageInfo", pageInfo);
        return "salary/list";
    }


    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           salaryService.delete(id);
        }
        return "redirect:/salary/list";
    }


    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Salary salary) {
        if (salary.getId() == null) {
            salaryService.save(salary);
        } else {
            salaryService.update(salary);
        }
        return "redirect:/salary/list";
    }


    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("salary",salaryService.get(id));
        }
        return "salary/input";
    }
}
